<%@page language="java" import="java.util.*" pageEncoding="utf-8" %>
<!doctype html>
<%
		String key = request.getRemoteAddr();
		String token = (String)session.getAttribute(key);
		out.print(token);
//		Map map = (Map)application.getAttribute("users");
//		Set set = map.keySet();
//		Iterator it = set.iterator();
//		while(it.hasNext()) {
//			String str = (String)it.next();
//			if(key.equals(str)) {
//				token = (String)map.get(str);
//				break;
//			}
//		}
//		String friendId = "";
//		if(null != request.getAttribute("friendId") && !"".equals(request.getAttribute("friendId"))) {
//			friendId = (String)request.getAttribute("friendId");
//		}
//		if(application.getAttribute("friendId")!=null && !"".equals(application.getAttribute("friendId"))) {
//			friendId = (String)application.getAttribute("friendId");
//		}
	%>
<html>
  <head>
    <title>index</title>
    <script type="text/javascript" src="/_ah/channel/jsapi"></script>
  </head>

  <body>
  <h1>欢迎</h1>
	<script type="text/javascript">
	var pid = "";
	sendMessage = function(path,opt_param) {
		var xhr = new XMLHttpRequest();
		path += "?msg="+ document.all.sendValue.value;
		xhr.open('POST', path, true);
		xhr.send();
	}
	
	onMessage = function(message) {
		document.all.receiveContent.value += message.data;
	}
	onOpened = function() {
		connected = true;
		alert('connected.');
	}
	
	onError = function(err) {
		alert(err.data);
	}
	
	onClose = function() {
		alert('此链接已经断开');
	}	
	
	channel = new goog.appengine.Channel('<%=token %>');
	socket = channel.open();
	socket.onopen = onOpened;
	socket.onmessage = onMessage;
	socket.onerror = onError;
	socket.onclose = onClose;
    	
    </script>
    <textarea name="receiveContent" rows="10" cols="50"></textarea>
    <textarea name='sendValue' rows='5' cols='10'></textarea>
    <input type="button" name="send" value="发送" onclick="sendMessage('/send','msg=aa')">
  </body>
</html>










